﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using Epi;

namespace CDC.SampleShell.Presentation
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App() : base()
        {
            LoadConfig();
        }

        // To use almost anything in the Epi Info 7 API, we have to first load the Epi Info 7 configuration. This is done
        // using the method below. This code typically doesn't have to change no matter what shell implementation/architecture
        // is chosen.
        protected bool LoadConfig()
        {
            string configFilePath = Configuration.DefaultConfigurationPath;
            bool configurationOk = true;
            try
            {
                string directoryName = System.IO.Path.GetDirectoryName(configFilePath);
                if (!Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                }

                if (!File.Exists(configFilePath))
                {
                    Configuration defaultConfig = Configuration.CreateDefaultConfiguration();
                    Configuration.Save(defaultConfig);
                }

                Configuration.Load(configFilePath);
            }
            catch (Epi.ConfigurationException)
            {
            }
            catch (Exception ex)
            {
                configurationOk = String.IsNullOrEmpty(ex.Message);
            }
            return configurationOk;
        }

        //public static new App Current
        //{
        //    get { return Application.Current as App; }
        //}
        //internal delegate void ApplicationInitializeDelegate(Splash splashWindow);
        //internal ApplicationInitializeDelegate ApplicationInitialize;
        //private void _applicationInitialize(Splash splashWindow)
        //{
        //    // Create the main window, but on the UI thread.
        //    Dispatcher.BeginInvoke(DispatcherPriority.Normal, new System.Action(delegate() 
        //    {
        //        MainWindow = new MainWindow();
        //        MainWindow.Show();
        //    }));
        //}
    }
}
